#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import warnings 
import os 
import json
import openpyxl
import pandas as pd
import requests
from bs4 import BeautifulSoup
from openpyxl.utils.dataframe import dataframe_to_rows
import time

def writer_to_text(list):  # 储存到text
    with open('result.txt', 'a', encoding='utf-8') as f:
        #f.write(json.dumps(list, ensure_ascii=False) + '\n')
        for key in list:
            f.write(key+ '\n')
        f.close()

def readFileIntoDict(name) :
    ls = []
    try:
        f = open(name, 'r')
        #print(f.read())
        for line in f.readlines():
            #print(line.strip())
            ls.append(line.strip())
    finally:
        if f:
            f.close()
    return ls
    

if __name__ == '__main__':
    lst = readFileIntoDict('/Users/archko/server.txt')
    bad = readFileIntoDict('/Users/archko/bad.txt')

    print("first:"+str(len(lst))+" second:"+ str(len(bad)))
    result =[]
    for item in bad:
        #print(item)
        for key in lst:
            if(key==item) :
                if (key in result):
                    print(key)
                else :
                    result.append(key)

    print("result:"+str(len(result)))
    writer_to_text(result)







